{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>.container { width:100% !important; }</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20181105\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>_id</th>\n",
       "      <th>date</th>\n",
       "      <th>long_openIntr</th>\n",
       "      <th>long_openIntr_chg</th>\n",
       "      <th>long_party_name</th>\n",
       "      <th>rank</th>\n",
       "      <th>short_openIntr</th>\n",
       "      <th>short_openIntr_chg</th>\n",
       "      <th>short_party_name</th>\n",
       "      <th>symbol</th>\n",
       "      <th>var</th>\n",
       "      <th>vol</th>\n",
       "      <th>vol_chg</th>\n",
       "      <th>vol_party_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5bf1ac3ab8037c5104904aa6</td>\n",
       "      <td>20181105</td>\n",
       "      <td>9962.0</td>\n",
       "      <td>-199.0</td>\n",
       "      <td>海通期货</td>\n",
       "      <td>1</td>\n",
       "      <td>8274.0</td>\n",
       "      <td>78.0</td>\n",
       "      <td>国泰君安</td>\n",
       "      <td>AP</td>\n",
       "      <td>AP</td>\n",
       "      <td>19826.0</td>\n",
       "      <td>-10762.0</td>\n",
       "      <td>海通期货</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5bf1ac3ab8037c5104904aa7</td>\n",
       "      <td>20181105</td>\n",
       "      <td>8149.0</td>\n",
       "      <td>123.0</td>\n",
       "      <td>一德期货</td>\n",
       "      <td>2</td>\n",
       "      <td>8161.0</td>\n",
       "      <td>126.0</td>\n",
       "      <td>永安期货</td>\n",
       "      <td>AP</td>\n",
       "      <td>AP</td>\n",
       "      <td>11339.0</td>\n",
       "      <td>-3051.0</td>\n",
       "      <td>华泰期货</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5bf1ac3ab8037c5104904aa8</td>\n",
       "      <td>20181105</td>\n",
       "      <td>7392.0</td>\n",
       "      <td>-222.0</td>\n",
       "      <td>中信期货</td>\n",
       "      <td>3</td>\n",
       "      <td>7860.0</td>\n",
       "      <td>-169.0</td>\n",
       "      <td>方正中期</td>\n",
       "      <td>AP</td>\n",
       "      <td>AP</td>\n",
       "      <td>10404.0</td>\n",
       "      <td>-5961.0</td>\n",
       "      <td>光大期货</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5bf1ac3ab8037c5104904aa9</td>\n",
       "      <td>20181105</td>\n",
       "      <td>6486.0</td>\n",
       "      <td>433.0</td>\n",
       "      <td>永安期货</td>\n",
       "      <td>4</td>\n",
       "      <td>6911.0</td>\n",
       "      <td>-112.0</td>\n",
       "      <td>华泰期货</td>\n",
       "      <td>AP</td>\n",
       "      <td>AP</td>\n",
       "      <td>9663.0</td>\n",
       "      <td>-4588.0</td>\n",
       "      <td>东证期货</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5bf1ac3ab8037c5104904aaa</td>\n",
       "      <td>20181105</td>\n",
       "      <td>6328.0</td>\n",
       "      <td>249.0</td>\n",
       "      <td>鲁证期货</td>\n",
       "      <td>5</td>\n",
       "      <td>6697.0</td>\n",
       "      <td>240.0</td>\n",
       "      <td>申银万国</td>\n",
       "      <td>AP</td>\n",
       "      <td>AP</td>\n",
       "      <td>7787.0</td>\n",
       "      <td>-4494.0</td>\n",
       "      <td>徽商期货</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        _id      date  long_openIntr  long_openIntr_chg  \\\n",
       "0  5bf1ac3ab8037c5104904aa6  20181105         9962.0             -199.0   \n",
       "1  5bf1ac3ab8037c5104904aa7  20181105         8149.0              123.0   \n",
       "2  5bf1ac3ab8037c5104904aa8  20181105         7392.0             -222.0   \n",
       "3  5bf1ac3ab8037c5104904aa9  20181105         6486.0              433.0   \n",
       "4  5bf1ac3ab8037c5104904aaa  20181105         6328.0              249.0   \n",
       "\n",
       "  long_party_name  rank  short_openIntr  short_openIntr_chg short_party_name  \\\n",
       "0            海通期货     1          8274.0                78.0             国泰君安   \n",
       "1            一德期货     2          8161.0               126.0             永安期货   \n",
       "2            中信期货     3          7860.0              -169.0             方正中期   \n",
       "3            永安期货     4          6911.0              -112.0             华泰期货   \n",
       "4            鲁证期货     5          6697.0               240.0             申银万国   \n",
       "\n",
       "  symbol var      vol  vol_chg vol_party_name  \n",
       "0     AP  AP  19826.0 -10762.0           海通期货  \n",
       "1     AP  AP  11339.0  -3051.0           华泰期货  \n",
       "2     AP  AP  10404.0  -5961.0           光大期货  \n",
       "3     AP  AP   9663.0  -4588.0           东证期货  \n",
       "4     AP  AP   7787.0  -4494.0           徽商期货  "
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pymongo\n",
    "import pandas as pd\n",
    "from pandas import Series,DataFrame\n",
    "import matplotlib as plt\n",
    "import matplotlib.dates as mdate\n",
    "import datetime\n",
    "\n",
    "from IPython.core.display import display, HTML\n",
    "display(HTML(\"<style>.container { width:100% !important; }</style>\"))\n",
    "#二行即可搞定画图中文乱码\n",
    "plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签\n",
    "plt.rcParams['axes.unicode_minus']=False #用来正常显示负号\n",
    "pd.set_option('display.width', None)  # 设置字符显示宽度\n",
    "pd.set_option('display.max_rows', None)  # 设置显示最大行\n",
    "pd.set_option('display.max_columns', None)  # 设置显示最大行\n",
    "\n",
    "#连接数据库\n",
    "client = pymongo.MongoClient('localhost',27017)\n",
    "futures = client.futures\n",
    "market = futures.market\n",
    "unit = futures.unit\n",
    "position = futures.position\n",
    "\n",
    "\n",
    "#加载数据\n",
    "\n",
    "\n",
    "date=datetime.date(2018, 11, 5).strftime('%Y%m%d')\n",
    "print(date)\n",
    "position = DataFrame(list(position.find({'date' : {'$gte':date}})))\n",
    "position.head()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
